C++ string中find() ,rfind() 等函数 用法总结及示例 | 您所在的位置:网站首页 › string rfind返回值 › C++ string中find() ,rfind() 等函数 用法总结及示例 |
string中 find()的应用 (rfind()
原型如下:
(1)size_t find (const string& str, size_t pos = 0) const; //查找对象--string类对象
(2)size_t find (const char* s, size_t pos = 0) const; //查找对象--字符串
(3)size_t find (const char* s, size_t pos, size_t n) const; //查找对象--字符串的前n个字符
(4)size_t find (char c, size_t pos = 0) const; //查找对象--字符
结果:找到 -- 返回 第一个字符的索引
没找到--返回 string::npos
示例:
#include // std::cout #include // std::string int main () { std::string str ("There are two needles in this haystack with needles."); std::string str2 ("needle"); // different member versions of find in the same order as above: std::size_t found = str.find(str2); if (found!=std::string::npos) std::cout |
CopyRight 2018-2019 实验室设备网 版权所有 |